package com.jm.offer.easy;

/**
 * @Description https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/
 * @date 2022/4/12 14:03
 */
public class _21调整数组顺序使奇数位于偶数前面 {
    public static void main(String[] args) {
        int[] exchange = exchange(new int[]{1, 2, 3, 4, 5, 6});
        for (int i = 0; i < exchange.length; i++) {
            System.out.println(exchange[i]);
        }
    }
    public static int[] exchange(int[] nums) {
        int[] rets = new int[nums.length];
        int start = 0;
        int end = nums.length;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] % 2 == 0){
                rets[--end] = nums[i];
            }else {
                rets[start++] = nums[i];
            }
        }
        return rets;
    }
}
